package com.sq.goodline.util;

import java.util.concurrent.ConcurrentHashMap;

public class ContextUtil {

	private static ThreadLocal<ConcurrentHashMap> threadContext=new ThreadLocal();
	
	public static <T> T getThreadContext(Object key,Class<T> t )
	{
		ConcurrentHashMap map=threadContext.get();
		if(map==null)
			return null;
		return (T) map.get(key);
		
	}
	public static void putThreadContext(Object key,Object v)
	{
		ConcurrentHashMap map=threadContext.get();
		if(map==null)
		{
			map=new ConcurrentHashMap();
			threadContext.set(map);
		}
		map.put(key, v);
	}
	
	public static Object removeThreadContext(Object key )
	{
		ConcurrentHashMap map=threadContext.get();
		if(map==null)
			return null;
		return  map.remove(key);
	}
}
